package cn.trigram.example.designpattern.facade;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.util.Random;

//库存子系统
public class Stock {

  boolean hasStock(String product) {

    try {
      SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
      random.setSeed(random.generateSeed(Math.abs(product.hashCode())));
      random.nextInt();
      return random.nextInt() > 0;//模拟是否还有库存
    } catch (NoSuchAlgorithmException | NoSuchProviderException ex) {
      // 处理异常
    }
    return false;
  }

}